package com.tm.utils;

import com.tm.enums.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @PROJECT_NAME: tm-wm-syb
 * @DESCRIPTION:
 * @USER: DELL
 * @DATE: 2023/4/3 14:51
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class R {
    private int code;
    private String msg;
    private Object data;


    public R(ResultEnum resultEnum){
       this.code = resultEnum.getCode();
       this.msg = resultEnum.getMsg();
    }

    public R(ResultEnum resultEnum,Object data){
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMsg();
        this.data = data;
    }

    public static R  success(Object data){

        return new R(ResultEnum.SUCCESS,data);
    }


    public static R  success(){

        return new R(ResultEnum.SUCCESS);
    }

    public static R  error(){

        return new R(ResultEnum.ERROR);
    }

    public static R  error(ResultEnum resultEnum){

        return new R(resultEnum);
    }

    public static R  error(int code, String msg){

        return new R(code,msg,null);
    }
}
